﻿using OfficeClip.OpenSource.StyleFix.Drivers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using OfficeClip.OpenSource.StyleFix;
using System.Collections.Generic;

namespace StyleFixUnitTest
{


    /// <summary>
    ///This is a test class for NamingRulesTest and is intended
    ///to contain all NamingRulesTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MaintainabilityRulesTest
    {
        private TestContext testContextInstance;
        private MaintainabilityRules target;
        private SAObject saObject;
        private List<SAObject> saObjects;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public MaintainabilityRulesTest()
        {
            target = new MaintainabilityRules();
            target.ForceAllow = true;
            saObject = new SAObject(string.Empty, 1, 1, string.Empty, false);
        }

        /// <summary>
        ///A test for SA1400_AccessModifierMustBeDeclared
        ///</summary>
        [TestMethod()]
        public void SA1400_AccessModifierMustBeDeclaredTest()
        {
            List<SAObject> noViolations = new List<SAObject>();
            List<SFWorkingLine> workingLines = new List<SFWorkingLine>();
            var classViolations = new List<SAObject>();
            var classViolation = new SAObject("SA1400", 0, 0, "The class must have an access modifier.", false);
            classViolations.Add(classViolation);
            var ctorViolations = new List<SAObject>();
            var ctorViolation = new SAObject("SA1400", 0, 0, "The constructor must have an access modifier.", false);
            ctorViolations.Add(ctorViolation);
            var fieldViolations = new List<SAObject>();
            var fieldViolation = new SAObject("SA1400", 0, 0, "The field must have an access modifier.", false);
            fieldViolations.Add(fieldViolation);
            var methodViolations = new List<SAObject>();
            var methodViolation = new SAObject("SA1400", 0, 0, "The method must have an access modifier.", false);
            methodViolations.Add(methodViolation);

            // test catch
            SFWorkingLine workingLine = new SFWorkingLine(1, "class messy : IDisposable {//No idea what's going on here { test confusion", false, classViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(2, "    messy(){", false, ctorViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(3, "/*Commented out this test for", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(4, "{ chars in favour of something vomit worthy", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(5, "if (\"{{\" == \"{{\")", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(6, "*/", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(7, "", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(8, "                if (\"\r\n\\\"{\" == @\"", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(9, "\"\"{\")", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(10, "                {", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(11, "                }", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(12, "}", false, noViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(13, "    int field;", false, fieldViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(14, "void method(){", false, methodViolations);
            workingLines.Add(workingLine);
            workingLine = new SFWorkingLine(15, "field = 1;}}", false, noViolations);
            workingLines.Add(workingLine);
            List<SFWorkingLine> workingLinesExpected = new List<SFWorkingLine>();
            SFWorkingLine workingLineExpected = new SFWorkingLine(1, "internal class messy : IDisposable {//No idea what's going on here { test confusion", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(2, "    protected messy(){", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(3, "/*Commented out this test for", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(4, "{ chars in favour of something vomit worthy", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(5, "if (\"{{\" == \"{{\")", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(6, "*/", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(7, "", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(8, "                if (\"\r\n\\\"{\" == @\"", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(9, "\"\"{\")", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(10, "                {", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(11, "                }", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(12, "}", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(13, "    private int field;", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(14, "private void method(){", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            workingLineExpected = new SFWorkingLine(15, "field = 1;}}", false, noViolations);
            workingLinesExpected.Add(workingLineExpected);
            // run code
            target.SA1400_AccessModifierMustBeDeclared(ref workingLines);
            // asserts
            Assert.AreEqual(workingLinesExpected[0].Line, workingLines[0].Line);
            Assert.AreEqual(workingLinesExpected[1].Line, workingLines[1].Line);
            Assert.AreEqual(workingLinesExpected[2].Line, workingLines[2].Line);
            Assert.AreEqual(workingLinesExpected[3].Line, workingLines[3].Line);
            Assert.AreEqual(workingLinesExpected[4].Line, workingLines[4].Line);
            Assert.AreEqual(workingLinesExpected[5].Line, workingLines[5].Line);
            Assert.AreEqual(workingLinesExpected[6].Line, workingLines[6].Line);
            Assert.AreEqual(workingLinesExpected[7].Line, workingLines[7].Line);
            Assert.AreEqual(workingLinesExpected[8].Line, workingLines[8].Line);
            Assert.AreEqual(workingLinesExpected[9].Line, workingLines[9].Line);
            Assert.AreEqual(workingLinesExpected[10].Line, workingLines[10].Line);
            Assert.AreEqual(workingLinesExpected[11].Line, workingLines[11].Line);
            Assert.AreEqual(workingLinesExpected[12].Line, workingLines[12].Line);
            Assert.AreEqual(workingLinesExpected[13].Line, workingLines[13].Line);
            Assert.AreEqual(workingLinesExpected[14].Line, workingLines[14].Line);
        }
    }
}
